# -*- coding: utf-8 -*-

import abc

from worker import Worker


class DaemonizeWorker(Worker):

    def run(self, params=None):
        ok = True
        while ok:
            ok = False if self._run(params) is False else True
            ok = False if self._cfg.get('force_run_once', False) is True else True

            sleep_time = self._cfg.get('run_sleep_time', 0)
            if int(sleep_time) > 0:
                self.sleep(sleep_time)

    @abc.abstractmethod
    def _run(self, params=None):
        raise NotImplementedError('call to abstract method %s._run' % self.__class__)
